/*
 * @Author: YuDianyun
 * @Email: 44208156@qq.com
 * @Date: 2020-06-02 09:00:00
 * @Last Modified by: YuDianyun
 * @Last Modified time: 2020-06-03 16:00:00
 * @Description: 课程发布
 */
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_code_framework/base/base_main_tabbar.dart';
import 'package:flutter_code_framework/base/base_widget.dart';
import 'package:flutter_code_framework/model_data/book/book.dart';
import 'package:flutter_code_framework/model_data/bookmenu/bookmenu.dart';
import 'package:flutter_code_framework/model_data/lessoninfo/lessoninfo.dart';
import 'package:flutter_code_framework/network/req_lesson_publish.dart';
import 'package:flutter_code_framework/pages/class/class_list_pop_page.dart';
import 'package:flutter_code_framework/pages/lesson/homework_student_list.dart';
import 'package:flutter_code_framework/pages/lesson/lesson_publish_event.dart';
import 'package:flutter_code_framework/pages/lesson/lesson_review.dart';
import 'package:flutter_code_framework/pages/lesson/lesson_tw_page.dart';
import 'package:flutter_code_framework/pages/lesson/lesson_xzy_page.dart';
import 'package:flutter_code_framework/pages/lesson/public_video_lesson.dart';
import 'package:flutter_code_framework/pages/lesson/lesson_audio_page.dart';
import 'package:flutter_code_framework/pages/lessons_page.dart';
import 'package:flutter_code_framework/route/route_transition.dart';
import 'package:flutter_code_framework/utils/global.dart';
import 'package:flutter_code_framework/widgets/x_dialog_page.dart';
import 'package:flutter_sfsymbols/flutter_sfsymbols.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:progress_dialog/progress_dialog.dart';
import 'package:percent_indicator/percent_indicator.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'common/select_book_menu.dart';

class LessonPublish extends BaseWidget {
  String lessonType;
  String id;
  LessonPublish({Key key, this.lessonType, this.id}) : super(key: key);

  @override
  BaseWidgetState<BaseWidget> getState() {
    return _LessonPublishState(lessonType: this.lessonType, id: this.id);
  }
}

class _LessonPublishState extends BaseWidgetState<LessonPublish> {
  var publishTypeArr = ["图文", "音频", "视频", "小作业"];
  StreamSubscription _subscription;
  String id;
  String lessonType;
  List<File> images;
  String audioPath;
  String oldAudioPath;
  String videoPath;
  String oldVideoPath;
  bool isLoadFinish = false;

  List<String> oldImages = [];
  List<String> firstImages = [];
  List<PicList> lstImages = [];
  String contentInfo;
  String oldContentInfo;
  int classCnt = 0;
  String classIds = "";
  String menuIds = "";
  String ownMenuIds = "";
  String bookMenuName = "";
  int audioTimeLength = 0;

  String bookId;
  String bookName;

  double progress = 0.0;

  bool enabledPublish = true;
  _LessonPublishState({Key key, this.lessonType, this.id}) {}

  ProgressDialog pr;
  @override
  void initState() {
    super.initState();
    id = this.id;
    getShareBook();

    if (id != null && id != "") {
      _getPrelessonInfoById(id);
    } else {
      setState(() {
        isLoadFinish = true;
      });
    }

    _subscription = G.eventBus.on<LessonPublishEvent>().listen((event) {
      print("--------------------------------------");
      if (lessonType == "图文" || lessonType == "小作业") {
        this.oldImages = event.oldImages;
        this.contentInfo = event.contentInfo;
        this.images = event.images;
      } else if (lessonType == "音频") {
        this.audioPath = event.audioPath;
        this.audioTimeLength = event.audioTimeLength;
      } else if (lessonType == "视频") {
        this.videoPath = event.videoPath;
      }
    });
  }

  void setShareBook(String userId) async {
    SharedPreferences _references = await SharedPreferences.getInstance();
    _references.setString("key_prelesson_bookid_" + userId, this.bookId);
    _references.setString("key_prelesson_bookname_" + userId, this.bookName);
    // print("setShareBook bookId:"+bookId);
    // print("setShareBook bookName:"+bookName);
  }

  void getShareBook() async {
    SharedPreferences _references = await SharedPreferences.getInstance();
    var userid = "";
    if (G.user != null && G.user.data != null && G.user.data.userId != null) {
      userid = G.user.data.userId;
    }
    bookId = _references.getString("key_prelesson_bookid_" + userid);
    bookName = _references.getString("key_prelesson_bookname_" + userid);

    if (bookId == null || bookId == "") {
      G.req.bookData
          .getBookList(
        schoolId: G.user.data.schoolId.toString(),
        periodId: G.user.data.periodId.toString(),
        subjectId: G.user.data.subjectId.toString(),
        gradeId: G.user.data.gradeId.toString(),
      )
          .then((value) {
        if (value != null &&
            value.data["bookList"] != null &&
            value.data["bookList"].length > 0) {
          var list =
              value.data["bookList"].map((e) => Book.fromJson(e)).toList();
          print("list:" + list.toString());
          if (list != null && list.length > 0) {
            Book book = list[0];
            this.bookId = book.id.toString();
            this.bookName = book.name.toString();
            setShareBook(userid);
          }
        }
      });
    }
  }

  _getPrelessonInfoById(id) async {
    // progress = 0.0;
    // pr = ProgressDialog(
    //   context,
    //   type: ProgressDialogType.Normal,
    //   isDismissible: true,
    // );
    // pr.style(
    //   message: '',
    //   borderRadius: 10.0,
    //   backgroundColor: Colors.white,
    //   progressWidget: CircularProgressIndicator(),
    //   // LinearPercentIndicator(
    //   //   backgroundColor: Colors.transparent,
    //   //   width: MediaQuery.of(context).size.width - 140,
    //   //   //animation: true,
    //   //   lineHeight: 30.0,
    //   //   //animationDuration: 2500,
    //   //   percent: progress,
    //   //   center: Text("$progress%"),
    //   //   linearStrokeCap: LinearStrokeCap.roundAll,
    //   //   progressColor: Colors.green,
    //   // ),
    //   elevation: 10.0,
    //   insetAnimCurve: Curves.easeInOut,
    //   progress: 0.0,
    //   maxProgress: 100,
    //   progressTextStyle: TextStyle(
    //       color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
    //   messageTextStyle: TextStyle(
    //       color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600),
    // );

    // await pr.show();

    await G.req.lessonPublishData.publishInfo(prelessonId: id).then((response) {
      if (response.statusMessage == "OK" && response.data != null) {
        setState(() {
          menuIds = response.data["menuIds"];
          classIds = response.data["rangeClassIds"];
          classCnt = classIds.split(",").length - 1;
          oldContentInfo = contentInfo = response.data["contentInfo"];
          if (response.data["picList"] != null &&
              response.data["picList"] != "") {
            var lst = response.data["picList"]
                .map((e) => PicList.fromJson(e))
                .toList();
            for (var item in lst) {
              PicList m = item;
              oldImages.add(m.filePath);
              firstImages.add(m.filePath);
              lstImages.add(m);
            }
          }
          // if (response.data["file"] != null) {
          //   var file = response.data["file"];
          // }
          oldAudioPath = audioPath = response.data["audioPath"];
          oldVideoPath = videoPath = response.data["videoPath"];
          audioTimeLength = response.data["audioTimeLength"];
          isLoadFinish = true;
        });
      }
    });
    //pr.hide();
  }

  //项部导航左箭头返回
  @override
  topNavPop() {
    if (widget.id != null && widget.id != "") {
      if (widget.lessonType == "音频") {
        if (oldAudioPath != audioPath) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
        } else {
          Navigator.of(context).pop();
        }
      } else if (widget.lessonType == "视频") {
        if (oldVideoPath != videoPath) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
        } else {
          Navigator.of(context).pop();
        }
      } else if (widget.lessonType == "图文" || widget.lessonType == "小作业") {
        if (checkQuitTWAndXzy() == false) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
        } else {
          Navigator.of(context).pop();
        }
      }
    } else {
      Navigator.of(context).pop();
    }
  }

  @override
  Future<bool> willPop() {
    if (widget.id != null && widget.id != "") {
      if (widget.lessonType == "音频") {
        if (oldAudioPath != audioPath) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
          return new Future.value(false);
        } else {
          return new Future.value(true);
        }
      } else if (widget.lessonType == "视频") {
        if (oldVideoPath != videoPath) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
          return new Future.value(false);
        } else {
          return new Future.value(true);
        }
      } else if (widget.lessonType == "图文" || widget.lessonType == "小作业") {
        if (checkQuitTWAndXzy() == false) {
          // RouteTransition(XDialogPage(
          //   '是否放弃修改？',
          //   callBack: () {
          //     RouteTransition(BaseMainTabbarPage())
          //         .pushAndRemoveUntilTransRoute(context);
          //   },
          // )).pushTransRoute(context);
          G.showToastDialog(context, "是否放弃修改？", title: "提示", callBack: () {
                Navigator.pop(context);
      });
          return new Future.value(false);
        } else {
          return new Future.value(true);
        }
      }
    }
    return new Future.value(true);
  }

  @override
  Widget buildWidget(BuildContext context) {
    print("widget.type:" + this.lessonType);
    print("index:" + publishTypeArr.indexOf(this.lessonType).toString());
    var idx = publishTypeArr.indexOf(this.lessonType);
    Widget widget;
    var isNew = false;
    if (id == null || id == "") {
      isNew = true;
    }
    if (idx == 0) {
      if (isNew) {
        widget = LessonTWPage();
      } else {
        widget =
            LessonTWPage(id: id, urlImages: oldImages, content: contentInfo);
      }
    } else if (idx == 1) {
      if (isNew) {
        widget = LessonAudioPage();
      } else {
        Map args = new Map();
        args["audioPath"] = audioPath;
        args["audioTimeLength"] = audioTimeLength;
        widget = LessonAudioPage(args: args);
      }
    } else if (idx == 2) {
      if (isNew) {
        widget = PublicVideoLesson();
      } else {
        widget = PublicVideoLesson(videoPath: videoPath);
      }
    } else if (idx == 3) {
      if (isNew) {
        widget = LessonXZYPage();
      } else {
        widget =
            LessonXZYPage(id: id, urlImages: oldImages, content: contentInfo);
      }
    }
    return FlutterEasyLoading(
        child: Container(
            alignment: Alignment.center,
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Column(
              children: <Widget>[
                Expanded(child: isLoadFinish ? widget : Container()),
                Container(
                  height: 80.0,
                  child: Column(
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.only(top: 0.0),
                          child: InkWell(
                            child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  Container(
                                    child: Row(
                                      children: <Widget>[
                                        Container(
                                          margin: EdgeInsets.only(left: 24.0),
                                          child: Icon(SFSymbols.person_3,
                                              color: G.ADColor("#39876E")),
                                        ),
                                        Container(
                                          margin: EdgeInsets.only(left: 5),
                                          child: Text('发布给谁',
                                              style: TextStyle(
                                                  color: G.ADColor("#767676"),
                                                  fontSize: 18.0)),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Container(
                                    child: Row(
                                      children: <Widget>[
                                        Container(
                                          child: Text(
                                              "(${classCnt.toString()})",
                                              style: TextStyle(
                                                  color: G.ADColor("#7D7D7D"),
                                                  fontSize: 20)),
                                        ),
                                        Container(
                                            child: IconButton(
                                                icon: Icon(
                                                    SFSymbols.chevron_right,
                                                    color:
                                                        G.ADColor("#000000")),
                                                onPressed: null))
                                      ],
                                    ),
                                  )
                                ]),
                            onTap: _receiver,
                          )),
                      isNew
                          ? Container()
                          : Container(
                              child: InkWell(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Container(
                                      child: Icon(SFSymbols.tray_arrow_up_fill,
                                          size: 14,
                                          color: G.ADColor("#EC7364")),
                                    ),
                                    SizedBox(width: 5),
                                    Container(
                                      child: Text("查看学习情况",
                                          style: TextStyle(
                                              color: G.ADColor("#767676"),
                                              fontSize: 14)),
                                    )
                                  ],
                                ),
                                onTap: _review,
                              ),
                            )
                    ],
                  ),
                )
              ],
            )));
  }

  void _selectMenu() {
    //选择章节
    showBottomSheetDialog(new SelectBookMenu(
        bookId: bookId,
        bookName: bookName,
        selectids: null,
        callback: selectmenucallback));
  }

  GetSelectedBookMenu selectmenucallback(List<BookMenu> selectlist) {
    if (selectlist != null && selectlist.length > 0) {
      List<String> ids = new List<String>();
      for (var item in selectlist) {
        ids.add(item.id.toString());
        bookMenuName = item.name;
      }
      menuIds = ids.join(",");
    } else {
      menuIds = "";
      bookMenuName = "";
    }
  }

  // _onReceiveProgress(int receive, int total) {
  //   setState(() {
  //     progress = receive * 100.0 / total;
  //     pr.update(
  //         progress: this.progress,
  //         message: "加载" + progress.ceil().toString() + "%");
  //   });
  // }

  bool checkQuitTWAndXzy() {
    if (oldContentInfo != contentInfo) {
      return false;
    }

    var tmpImages = List<String>();
    if (lessonType == "图文" || lessonType == "小作业") {
      if (this.oldImages != null && this.oldImages.length > 0) {
        for (var one in this.oldImages) {
          if (one != "+" && one.indexOf("http") > -1) {
            tmpImages.add(one);
          }
        }
      }
    }

    if (tmpImages.length == firstImages.length) {
      for (int i = 0; i < firstImages.length; i++) {
        if (tmpImages[i] != firstImages[i]) {
          return false;
        }
      }
    } else {
      return false;
    }

    if (images != null && images.length > 0) {
      return false;
    }
    return true;
  }

  _onSendProgress(int send, int total) {
    setState(() {
      progress = send * 100.0 / total;
      pr.update(
          progress: this.progress,
          message: "完成" + progress.ceil().toString() + "%");
      //EasyLoading.showProgress(progress, status: "${(progress*100).toStringAsFixed(0)}%");
      //maxprogress = total * 1.0;
    });
  }

  //发布课程
  void _publish() async {
    var tmpImages = List<String>();
    var delModuleDetailIds = List<String>();

    if (lessonType == "图文" || lessonType == "小作业") {
      if (this.oldImages != null && this.oldImages.length > 0) {
        for (var one in this.oldImages) {
          if (one != "+" && one.indexOf("http") > -1) {
            tmpImages.add(one);
          }
        }
      }
    }
    switch (lessonType) {
      case "图文":
        if (tmpImages.length > 0) {
        } else if (images != null && images.length > 0) {
        } else if (contentInfo != null && contentInfo.trim().length > 0) {
        } else {
          showNormalToast("图文至少有一项有内容");
          return;
        }
        break;
      case "音频":
        if (audioPath != null && audioPath != "") {
          images = new List<File>();
          images.add(new File(audioPath));
        } else {
          showNormalToast("没有找到音频");
          return;
        }
        break;
      case "视频":
        if (videoPath != null && videoPath != "") {
          images = new List<File>();
          images.add(new File(videoPath));
        } else {
          showNormalToast("没有找到视频");
          return;
        }
        break;
      case "小作业":
        if (tmpImages.length > 0) {
        } else if (images != null && images.length > 0) {
        } else if (contentInfo != null && contentInfo.trim().length > 0) {
        } else {
          showNormalToast("小作业至少有一项有内容");
          return;
        }
        break;
    }

    if (classCnt == 0) {
      showNormalToast("请选择你发布的班级");
      return;
    }

    if (bookId == null || bookId == "") {
      showNormalToast("请选择教材");
      return;
    }

    if (menuIds == "") {
      _selectMenu();
      return;
    }
    setState(() {
      enabledPublish = false;
    });

    // EasyLoading.show(
    //     status: "正在处理中..."); //indicator: CircularProgressIndicator());
    // EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
    // EasyLoading.instance.maskType = EasyLoadingMaskType.clear;
    // EasyLoading.instance.indicatorType = EasyLoadingIndicatorType.circle;

    // EasyLoading.show(
    //   indicator: LinearPercentIndicator(
    //     width: MediaQuery.of(context).size.width - 140,
    //     animation: true,
    //     lineHeight: 20.0,
    //     animationDuration: 2500,
    //     percent: progress,
    //     center: Text("$progress%"),
    //     linearStrokeCap: LinearStrokeCap.roundAll,
    //     progressColor: Colors.green,
    //   ),
    // );
    //EasyLoading.showProgress(progress, status: "$progress%");
    progress = 0.0;
    pr = ProgressDialog(
      context,
      type: ProgressDialogType.Normal,
      isDismissible: true,
    );
    pr.style(
      message: '',
      borderRadius: 10.0,
      backgroundColor: Colors.white,
      progressWidget: CircularProgressIndicator(),
      // LinearPercentIndicator(
      //   backgroundColor: Colors.transparent,
      //   width: MediaQuery.of(context).size.width - 140,
      //   //animation: true,
      //   lineHeight: 30.0,
      //   //animationDuration: 2500,
      //   percent: progress,
      //   center: Text("$progress%"),
      //   linearStrokeCap: LinearStrokeCap.roundAll,
      //   progressColor: Colors.green,
      // ),
      elevation: 10.0,
      insetAnimCurve: Curves.easeInOut,
      progress: 0.0,
      maxProgress: 100,
      progressTextStyle: TextStyle(
          color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
      messageTextStyle: TextStyle(
          color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600),
    );

    await pr.show();

    // pr.update(
    //   progressWidget: LinearPercentIndicator(
    //     backgroundColor: Colors.transparent,
    //     width: MediaQuery.of(context).size.width - 140,
    //     //animation: true,
    //     lineHeight: 10.0,
    //     //animationDuration: 2500,
    //     percent: progress,
    //     center: Text("$progress%"),
    //     linearStrokeCap: LinearStrokeCap.roundAll,
    //     progressColor: Colors.green,
    //   ),
    // );
    // await Future.delayed(Duration(seconds: 20));
    // pr.update(
    //   // progress: progress,
    //   // maxProgress: 100,
    //   progressWidget: LinearPercentIndicator(
    //     backgroundColor: Colors.transparent,
    //     width: MediaQuery.of(context).size.width - 140,
    //     //animation: true,
    //     lineHeight: 60.0,
    //     //animationDuration: 2500,
    //     percent: progress,
    //     center: Text("$progress%"),
    //     linearStrokeCap: LinearStrokeCap.roundAll,
    //     progressColor: Colors.green,
    //   ),
    // );

//新建
    if (id == null || id == "") {
      var response = await G.req.lessonPublishData.publishLesson(
        classIds: classIds,
        bookId: bookId,
        bookType: "教材",
        moduleType: lessonType,
        content: contentInfo,
        menuIds: menuIds,
        ownMenuIds: ownMenuIds,
        bookMenuName: bookMenuName,
        picFiles: images,
        audioTimeLength: audioTimeLength,
        progressCallback: _onSendProgress,
      );
      //EasyLoading.dismiss();
      pr.hide();
      //pr.hide().whenComplete(() {  print(pr.isShowing());});

      if (response.statusMessage == "OK") {
        showNormalToast("发布成功");
        RouteTransition(BaseMainTabbarPage())
            .pushAndRemoveUntilTransRoute(context);
      } else {
        showNormalToast("发布失败");
        setState(() {
          enabledPublish = false;
        });
      }
    } else {
      if (lessonType == "小作业") {
        if (lstImages != null && lstImages.length > 0) {
          for (var img in lstImages) {
            if (tmpImages.indexOf(img.filePath) < 0) {
              delModuleDetailIds.add(img.moduleDetailId);
            }
          }
        }
      }

      var response = await G.req.lessonPublishData.rePublishLesson(
        prelessonId: id,
        classIds: classIds,
        bookId: bookId,
        bookType: "教材",
        moduleType: lessonType,
        content: contentInfo,
        menuIds: menuIds,
        ownMenuIds: ownMenuIds,
        bookMenuName: bookMenuName,
        picFiles: images,
        audioTimeLength: audioTimeLength,
        progressCallback: _onSendProgress,
        oldImgsUrl: tmpImages.join(","),
        delModuleDetailIds: delModuleDetailIds.join(","),
      );
      //EasyLoading.dismiss();
      pr.hide();

      if (response.statusMessage == "OK") {
        showNormalToast("发布成功");
        RouteTransition(BaseMainTabbarPage())
            .pushAndRemoveUntilTransRoute(context);
      } else {
        showNormalToast("发布失败");
        setState(() {
          enabledPublish = false;
        });
      }
    }
  }

  Future<ByteData> getByteData(File file) async {
    Uint8List bytes = file.readAsBytesSync();
    return ByteData.view(bytes.buffer);
  }

  GetClassIds getClassIds(String classIds) {
    print("classIds:" + classIds);
    setState(() {
      this.classIds = classIds;
      classCnt = classIds.split(",").length - 1;
    });
    Navigator.pop(context);
  }

  //发布给谁
  void _receiver() {
    print("receiver");
    print("reClassIds：" + this.classIds);
    Navigator.of(context).push(new MaterialPageRoute(
        builder: (ctx) => new ClassListPopPage(
            callback: getClassIds, reClassIds: this.classIds)));
  }

  //查看学习情况
  void _review() {
    print("review");
    if (widget.lessonType == "小作业") {
      // Navigator.of(context).push(new MaterialPageRoute(
      //     builder: (ctx) => new HomeworkStudentList(preLessonId: widget.id)));
      RouteTransition(HomeworkStudentList(preLessonId: widget.id),
              trans: "downup-slide")
          .pushTransRoute(context);
    } else {
      // Navigator.of(context).push(new MaterialPageRoute(
      //     builder: (ctx) => new LessonReview(preLessonId: widget.id)));

      RouteTransition(LessonReview(preLessonId: widget.id),
              trans: "downup-slide")
          .pushTransRoute(context);
    }
  }

  @override
  void dispose() {
    _subscription.cancel(); //  一定要取消 避免内存泄露
    super.dispose();
  }

  @override
  void onCreate() {
    // log("onCreate");
    setAppTopNavBarVisible(true);

    //  setTopNavTitle("发布");
  }

  @override
  void onPause() {
    // log('onPause');
  }

  @override
  void onResume() {
    // log("onResume");
  }

  @override
  Widget getTopNavRightWidget(BuildContext _contextBaseFunction) {
    return Container(
      width: 62.0,
      height: 26.0,
      child: RaisedButton(
          // shape: RoundedRectangleBorder(
          //     side: BorderSide(
          //         color: Colors.transparent, style: BorderStyle.solid),
          //     borderRadius: BorderRadius.all(Radius.circular(6.0))),
          color: Color.fromARGB(255, 236, 115, 100),
          child: Text(
            '发 布',
            style: TextStyle(fontSize: 12, color: Colors.white),
          ),
          onPressed: enabledPublish ? _publish : null),
    );
  }
}
